package com.nuctech.androidhardwaredriver;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;

import android_gpio_api.GPIO;

public class MainActivity extends AppCompatActivity implements View.OnClickListener {

    /**
     * 蜂鸣器开
     */
    private Button mBtnOpen;
    /**
     * 蜂鸣器关
     */
    private Button mBtnClose;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        initView();

    }

    private void initView() {
        mBtnOpen = findViewById(R.id.btn_open);
        mBtnOpen.setOnClickListener(this);
        mBtnClose = findViewById(R.id.btn_close);
        mBtnClose.setOnClickListener(this);

        GPIO.exportGpio(224);
        GPIO.setGpioDirection(224, 1);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            default:
                break;
            case R.id.btn_open:
                GPIO.writeGpioStatus(224, 1);
                break;
            case R.id.btn_close:
                GPIO.writeGpioStatus(224, 0);
                break;
        }
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();

        GPIO.unexportGpio(224);
    }
}
